//
// Created by Administrator on 2024/10/17.
//

#ifndef UTILS_HPP
#define UTILS_HPP
#include <memory>

#include "../protocol/jtt809_packet.h"

namespace network {

typedef std::shared_ptr<protocol::Container<char>> serialize_t;

inline serialize_t serialize(JTT809Packet &packet) {
    protocol::MessagePackWriter writer(1024 > size(packet) ? 1024 : size(packet)+1024);
    packet.serialize(writer);
    const auto out = writer.flushAndGet();
    return std::make_shared<protocol::Container<char>>(out.get(), writer.size());
}
}

#endif //UTILS_HPP
